# Makefile for src/

SHELL = @SHELL@
top_srcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
depcomp = /bin/sh $(top_srcdir)/autotools/depcomp

@SET_MAKE@

CXXFLAGS = @CXXFLAGS@ -I.. -I$(top_srcdir) -I$(top_srcdir)/lib -I$(top_srcdir)/pack @DEFS@ $(CFLGS) '-DCOMMIT="$(COMMIT)"' '-DBRANCH="$(BRANCH)"' -DBUILDTS=$(BUILDTS) '-DVERSION="$(VERSION)"'
CPPFLAGS = @CPPFLAGS@

OBJCOPY = @OBJCOPY@

OBJS = auth.o \
	base64.o \
	binary.o \
	binds.o \
	bg.o \
	botcmd.o \
	botmsg.o \
	botnet.o \
	chanprog.o \
	cmds.o \
	core_binds.o \
	conf.o \
	crypt.o \
	dcc.o \
	dccutil.o \
	debug.o \
	egg_timer.o \
	enclink.o \
	EncryptedStream.o \
	flags.o \
	garble.o \
	log.o \
	main.o \
	match.o \
	misc.o \
	misc_file.o \
	net.o \
	adns.o \
	response.o \
	rfc1459.o \
	set.o \
	shell.o \
	socket.o \
	sprintf.o \
	userent.o \
	userrec.o \
	users.o

MODOBJS = mod/channels.o \
        mod/console.o \
        mod/ctcp.o \
        mod/irc.o \
        mod/server.o \
        mod/share.o \
        mod/transfer.o \
        mod/update.o


MAKE_GENERIC = $(MAKE) 'MAKE=$(MAKE)' 'MAKEFLAGS=$(MAKEFLAGS)' 'CXX=$(CXX)' 'LD=$(LD)' 'STRIP=$(STRIP)' 'CFLGS=$(CFLGS)' 'CCDEPMODE=$(CCDEPMODE)'

blah:
	@echo ""
	@echo "Use the build script."
	@echo ""

makeres: makeres.c ../lib/bdlib/src/libbdlib.a
	@echo -e "Compiling: \033[1mmakeres\033[0m"
	@$(CXX) $(CXXFLAGS) -I$(top_srcdir) -I$(top_srcdir)/pack $(CPPFLAGS) makeres.c ../lib/bdlib/src/libbdlib.a -o makeres
	@$(STRIP) makeres@EXEEXT@

makeset: makeset.c ../lib/bdlib/src/libbdlib.a
	@echo -e "Compiling: \033[1mmakeset\033[0m"
	@$(CXX) $(CXXFLAGS) -I$(top_srcdir) -I$(top_srcdir)/pack $(CPPFLAGS) makeset.c ../lib/bdlib/src/libbdlib.a -o makeset
	@$(STRIP) makeset@EXEEXT@

makehelp: makehelp.c ../lib/bdlib/src/libbdlib.a
	@echo -e "Compiling: \033[1mmakehelp\033[0m"
	@$(CXX) $(CXXFLAGS) -I$(top_srcdir) -I$(top_srcdir)/pack $(CPPFLAGS) makehelp.c ../lib/bdlib/src/libbdlib.a -o makehelp
	@$(STRIP) makehelp@EXEEXT@

sorthelp: sorthelp.c ../lib/bdlib/src/libbdlib.a
	@echo -e "Compiling: \033[1msorthelp\033[0m"
	@$(CXX) $(CXXFLAGS) -I$(top_srcdir) -I$(top_srcdir)/pack $(CPPFLAGS) sorthelp.c ../lib/bdlib/src/libbdlib.a -o sorthelp
	@$(STRIP) sorthelp@EXEEXT@

stringfix: stringfix.c common.h ../config.h eggdrop.h
	@echo -e "Compiling: \033[1mstringfix\033[0m"
	@$(CXX) $(CXXFLAGS) -I$(top_srcdir) -I$(top_srcdir)/pack $(CPPFLAGS) stringfix.c -o stringfix
	@$(STRIP) stringfix@EXEEXT@

#../$(EGGEXEC): build_msg $(OBJS) mycrypto compatability
../$(EGGEXEC): build_msg $(OBJS) mycrypto compatability ../lib/bdlib/src/libbdlib.a
	@echo "[*] Linking"
	@echo ""
	@echo "Linking wraith... $(EGGBUILD)"
	@echo ""
	$(LD) -o ../$(EGGEXEC) $(OBJS) $(MODOBJS) compat/*.o crypto/*.o ../lib/bdlib/src/libbdlib.a $(LIBS)
#	$(LD) -o ../$(EGGEXEC) $(OBJS) $(MODOBJS) $(LIBS) compat/*.o crypto/*.o
	@$(STRIP) ../$(EGGEXEC)
	@$(OBJCOPY) ../$(EGGEXEC)
	@echo "Successful compile: $(EGGEXEC)"
	@echo ""

$(EGGEXEC): stringfix ../$(EGGEXEC)

clean:
	@rm -f .depend *.o *~ _*.c

build_msg:
	@echo "[*] Compiling core components"

compatability:
	@echo "[*] Compiling compatability components"
	+@cd compat && $(MAKE_GENERIC) compat

mycrypto:
	@echo "[*] Compiling crypto"
	+@cd crypto && $(MAKE_GENERIC) crypto

include ./.deps/includes

.SUFFIXES:
.SUFFIXES: .c .h .o

.c.o: stringfix
	@echo -e "Compiling: \033[1m`basename $< .c`\033[0m"
	@./stringfix@EXEEXT@ $< _$< || cp -f $< _$<
	source='$<' object='$@' depfile='.deps/$*.Po' tmpdepfile='.deps/$*.TPo' depmode=$(CCDEPMODE) $(depcomp) \
	$(CXX) $(CXXFLAGS) $(CPPFLAGS) -c _$<  -o `basename $< .c`.o

#safety hash

